# vim:set noet ts=4:
#
# ibust - IBus with Traditional interface
#
# Copyright (c) 2013 Daniel Sun
# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
# Copyright (c) 2007-2010 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

NULL =

if ENABLE_TESTS
TESTS_DIR = tests
endif

SUBDIRS = . $(TESTS_DIR)

# libibust = libibust-@IBUST_API_VERSION@.la
libibust = libibust-1.0.la

# gobject introspection
-include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_SCANNER_ARGS =
INTROSPECTION_COMPILER_ARGS = \
    --includedir=$(srcdir)    \
    --includedir=.            \
    $(NULL)
INTROSPECTION_GIRS =
CLEANFILES =

# C preprocessor flags
AM_CPPFLAGS =                                   \
    -DG_LOG_DOMAIN=\"IBUST\"                     \
    @GLIB2_CFLAGS@                              \
    @GOBJECT2_CFLAGS@                           \
    @GIO2_CFLAGS@                               \
    -DIBUST_DATA_DIR=\"$(pkgdatadir)\"           \
    -DIBUST_COMPILATION                          \
    -DISOCODES_PREFIX=\"$(ISOCODES_PREFIX)\"    \
    $(NULL)

# ibust library
lib_LTLIBRARIES = $(libibust)

libibust_1_0_la_LIBADD =     \
    @GLIB2_LIBS@            \
    @GOBJECT2_LIBS@         \
    @GIO2_LIBS@             \
    $(NULL)
libibust_1_0_la_LDFLAGS =            \
    -no-undefined                   \
    -export-symbols-regex "ibust_.*" \
    -version-info @LT_VERSION_INFO@ \
    $(NULL)

ibust_sources =              \
    ibustshare.c             \
    ibustobject.c            \
    ibustserializable.c      \
    ibustproxy.c             \
    ibustservice.c           \
    ibustfactory.c           \
    ibustengine.c            \
    ibusterror.c             \
    ibusttext.c              \
    ibustkeymap.c            \
    ibustattribute.c         \
    ibustattrlist.c          \
    ibustproperty.c          \
    ibustproplist.c          \
    ibustlookuptable.c       \
    ibustinputcontext.c      \
    ibustconfig.c            \
    ibustconfigservice.c     \
    ibustpanelservice.c      \
    ibustbus.c               \
    ibustkeynames.c          \
    ibustkeyuni.c            \
    ibusthotkey.c            \
    ibustxml.c               \
    ibustenginedesc.c        \
    ibustobservedpath.c      \
    ibustcomponent.c         \
    ibustutil.c              \
    ibustenginesimple.c      \
    $(NULL)
libibust_1_0_la_SOURCES =    \
    ibustmarshalers.c        \
    ibustenumtypes.c         \
    $(ibust_sources)         \
    $(NULL)
ibust_marshalers_sources =   \
    ibustmarshalers.h        \
    ibustmarshalers.c        \
    $(NULL)
ibust_enumtypes_sources =    \
    ibustenumtypes.h         \
    ibustenumtypes.c         \
    $(NULL)
ibust_headers =              \
    ibust.h                  \
    ibustshare.h             \
    ibustdebug.h             \
    ibustobject.h            \
    ibustserializable.h      \
    ibustproxy.h             \
    ibustservice.h           \
    ibustfactory.h           \
    ibustengine.h            \
    ibusterror.h             \
    ibusttext.h              \
    ibustkeymap.h            \
    ibustattribute.h         \
    ibustattrlist.h          \
    ibustproperty.h          \
    ibustproplist.h          \
    ibustlookuptable.h       \
    ibustinputcontext.h      \
    ibustconfig.h            \
    ibustconfigservice.h     \
    ibustpanelservice.h      \
    ibustkeysyms.h           \
    ibustkeysyms-compat.h    \
    ibustkeys.h              \
    ibusttypes.h             \
    ibustbus.h               \
    ibusthotkey.h            \
    ibustxml.h               \
    ibustenginedesc.h        \
    ibustobservedpath.h      \
    ibustcomponent.h         \
    ibustutil.h              \
    ibustenginesimple.h      \
    $(NULL)
ibustincludedir = $(includedir)/ibust-@IBUST_API_VERSION@
ibust_public_headers =       \
    $(ibust_headers)         \
    ibustenumtypes.h         \
    ibustversion.h           \
    $(NULL)
ibustinclude_HEADERS =       \
    $(ibust_public_headers)  \
    $(NULL)
ibust_privite_headers =       \
    ibustinternal.h           \
    keyname-table.h          \
    gtkimcontextsimpleseqs.h \
    $(NULL)
noinst_HEADERS =            \
    $(ibust_privite_headers) \
    $(NULL)

BUILT_SOURCES =                 \
    $(ibust_marshalers_sources)  \
    $(ibust_enumtypes_sources)   \
    $(NULL)

if HAVE_INTROSPECTION
introspection_sources =         \
    $(ibust_headers)             \
    $(ibust_sources)             \
    $(NULL)
built_introspection_sources =   \
    $(ibust_enumtypes_sources)   \
    ibustversion.h               \
    $(NULL)
IBust-1.0.gir: $(libibust) Makefile
IBust_1_0_gir_SCANNERFLAGS = --pkg-export=ibust-1.0 $(IBUST_GIR_SCANNERFLAGS)
IBust_1_0_gir_INCLUDES = GLib-2.0 GObject-2.0 Gio-2.0
IBust_1_0_gir_LIBS = $(libibust)
IBust_1_0_gir_FILES =                                            \
    $(addprefix $(srcdir)/,$(introspection_sources))            \
    $(addprefix $(builddir)/,$(built_introspection_sources))    \
    $(NULL)
IBust_1_0_gir_CFLAGS = -DIBUST_COMPILATION -I$(srcdir) -I$(builddir)
INTROSPECTION_GIRS += IBust-1.0.gir

girdir = $(datadir)/gir-1.0
dist_gir_DATA = $(INTROSPECTION_GIRS)

typelibsdir = $(libdir)/girepository-1.0
typelibs_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)

CLEANFILES += $(dist_gir_DATA) $(typelibs_DATA)
endif

# gen enum types
ibustenumtypes.h: $(ibust_headers) ibustenumtypes.h.template
	$(AM_V_GEN) ( top_builddir=`cd $(top_builddir) && pwd`; \
	cd $(srcdir) && $(GLIB_MKENUMS) --template ibustenumtypes.h.template $(ibust_headers) | \
		sed 's/i_bust_/ibust_/g' | \
		sed 's/I_TYPE_BUST_/IBUST_TYPE_/g') > \
	ibustenumtypes.h.tmp && mv ibustenumtypes.h.tmp ibustenumtypes.h

ibustenumtypes.c: $(ibust_headers) ibustenumtypes.c.template
	$(AM_V_GEN) ( top_builddir=`cd $(top_builddir) && pwd`; \
	cd $(srcdir) && $(GLIB_MKENUMS) --template ibustenumtypes.c.template $(ibust_headers) | \
		sed 's/i_bust_/ibust_/g' | \
		sed 's/I_TYPE_BUST_/IBUST_TYPE_/g') > \
	ibustenumtypes.c.tmp && mv ibustenumtypes.c.tmp ibustenumtypes.c

# gen marshal
ibustmarshalers.h: ibustmarshalers.list
	$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_ibust_marshal $(srcdir)/ibustmarshalers.list --header --internal > $@.tmp && \
	mv $@.tmp $@

ibustmarshalers.c: ibustmarshalers.h ibustmarshalers.list
	$(AM_V_GEN) (echo "#include \"ibustmarshalers.h\""; \
	$(GLIB_GENMARSHAL) --prefix=_ibust_marshal $(srcdir)/ibustmarshalers.list --body --internal) > $@.tmp && \
	mv $@.tmp $@

EXTRA_DIST =                    \
    ibustversion.h.in            \
    ibustmarshalers.list         \
    ibustenumtypes.h.template    \
    ibustenumtypes.c.template    \
    $(NULL)

CLEANFILES +=                   \
    $(BUILT_SOURCES)            \
    stamp-ibustmarshalers.h      \
    stamp-ibustenumtypes.h       \
    $(NULL)

DISTCLEANFILES =                \
    ibustversion.h               \
    $(NULL)

-include $(top_srcdir)/git.mk
